<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>数据统计分析</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../layui.css" media="all">
  <link rel="stylesheet" href="../MDASS.css" media="all">
</head>
<body style="overflow-y: scroll;">
<div class="layui-tab"><!-- TAB页 -->
  <ul class="layui-tab-title">
    <li class="layui-this">已申报教材</li>
    <li>已征订教材</li>
    <li>统计分析</li>
  </ul>
  <div class="layui-tab-content">
  	<!-- TAB1 -->
  	<div class="layui-tab-item layui-show">
  	<div class="layui-row">
    <div class="layui-col-md6">
  		<button id="searchMaterial" data-method="search" class="layui-btn" style="float: left;margin-right: 10px">搜索</button>    
  		<input name="material_search" id="material_search" class="layui-input" type="text" style="float: left;width: 200px" >
	</div>
	</div>
    	<div>
      		<table class="layui-table" id = "userAnalysis" lay-filter="analysis" lay-data="{id: 'userAnalysis'}"></table>  
    	</div>
    </div>
    <!-- TAB2 -->
    <div class="layui-tab-item">
  	<div class="layui-row">
    <div class="layui-col-md6">
  		<button id="searchMaterial2" data-method="search2" class="layui-btn" style="float: left;margin-right: 10px">搜索</button>    
  		<input name="material_search2" id="material_search2" class="layui-input" type="text" style="float: left;width: 200px" >
	</div>
	</div>
    	<div>
      		<table class="layui-table" id = "userAnalysis2" lay-filter="analysis2" lay-data="{id: 'userAnalysis2'}"></table>  
    	</div>
    </div>
    <!-- TAB3 -->
    <div class="layui-tab-item">
    	<form class="layui-form" action="">
  		<div class="layui-form-item">
  			<div class="layui-inline">
    		<label class="layui-form-label">选择年份</label>
    		<div class="layui-input-inline">
      		<select name="interest" lay-filter="aihao" class="years" id="selectYears">
        		<option value=""></option>
      		</select>
    		</div>
    		<button class="layui-btn doAnalysis" style="float: left;margin-left: 10px" type="button" onclick="userAnalysis()">生成报表</button>
    		</div>
  	</div>
</form>
    	<div id = "userContainer" style="min-width: 400px;height: 400px"></div>
    </div>
  </div>
</div>


<script type="text/html" id="barDemo">
	<a data-method="setTop" class="layui-btn layui-btn-sm"  lay-event="showMessage" >查看</a>
</script>
<script type="text/html" id="barDemo2">
	<a data-method="setTop2" class="layui-btn layui-btn-sm"  lay-event="showMessage2" >查看</a>
</script>
<script src="../layui.js" charset="utf-8"></script>
<script src="../jquery-3.1.1.min.js"></script>
<script src="../highcharts-zh_CN.js"></script>
<script src="../highcharts.js"></script>
<script src="../exporting.js"></script>
<script>
$(function(){
	var dDate = new Date();
    var totalYear = dDate.getFullYear();

    var optionText;
    for(var i=5;i>0;i--){

    	var aimYears = totalYear-i;

    	optionText =optionText+"<option value="+aimYears+">"+aimYears+"</option>";

    }
    var nextYear = totalYear+1;

    optionText = optionText+"<option value="+totalYear+" selected=''>"+totalYear+"</option>"+"<option value="+nextYear+">"+nextYear+"</option>";
    $("#selectYears").append(optionText);
});
	layui.use(['table','layer','element','form'],function(){
	var form = layui.form;
	var element = layui.element;
	var table = layui.table;
	var layer =layui.layer;
	var loginName = "杨振刚";
	var tSerial = "30000001";
	var pageNum = 0;
	    table.render({
	        id:'userAnalysis',
	        elem: '#userAnalysis',
	        url:'/admin/material/MaByTName',
	        where:{"tName":loginName},
	        method:'post',
	        done: function(res, curr, count){
	        	pageNum = curr;
	          		},
	        cols:[[//标题栏
			{field:'name',width:150,title:'教材名称'},
			{field:'author',width:100,title:'作者'},
			{field:'versionNum',width:100,title:'版本号'},
			{field:'versionDate',width:150,title:'出版日期'},
			{field:'press',width:100,title:'出版社'},
			{field:'isbn',width:100,title:'ISBN'},
			{field:'nationalEX',width:150,title:'优秀教材（国家）'},
			{field:'provincialEX',width:150,title:'优秀教材（省）'},
			{fixed: 'right', width:150, align:'center', toolbar: '#barDemo'}
			]],
	        skin:'line',
	        even: true,
	        page:true,
	        limits:[5,10,15],
	        limit:5,//limit:5 每页显示的数量
	    });
	    table.on('tool(analysis)', function(obj){
	    	var data = obj.data;
	    	if(obj.event =='showMessage'){
	    		layer.open({
	    			type:1,
	    			title:false,
	    			colseBtn:false,
	    			area:'650px;',
	    			shade:0.8,
	    			id:'messageDetials', //设定一个id，防止重复弹出
	    			btn:['确定'],
	    			btnAlign: 'c',
	    			moveType: 1 ,//拖拽模式，0或者1
	    			content:'<div><table class="layui-table"><thead><tr><th>编号</th><th>申报人</th><th>所属课程</th><th>其他描述</th>'
	        			+'</tr></thead><tbody><tr><td>'+data.id+'</td>'
	        			+'<td>'+data.tName+'</td><td>'+data.courseSerial+'</td><td>'+data.script+'</td></tr></tbody></table></div>'
	    		});
	    	}
	    });
	    //TAB2
	    table.render({
	        id:'userAnalysis2',
	        elem: '#userAnalysis2',
	        url:'/admin/detials/byTName',
	        where:{"tName":loginName},
	        method:'post',
	        done: function(res, curr, count){
	        	pageNum = curr;
	          		},
	        cols:[[//标题栏
	        {field:'applySerial',width:150,title:'申请编号',sort:true},
			{field:'grade',width:250,title:'上课班级'},
			{field:'name',width:150,title:'教材名称'},
			{field:'quantity',width:100,title:'数量'},
			{field:'courseName',width:250,title:'课程名称'},
			{field:'telephone',width:100,title:'联系电话'},
			{fixed: 'right', width:150, align:'center', toolbar: '#barDemo2'}
			]],
	        skin:'line',
	        even: true,
	        page:true,
	        limits:[5,10,15],
	        limit:5,//limit:5 每页显示的数量
	    });
	    table.on('tool(analysis2)', function(obj){
	    	var data = obj.data;
	    	var objDate = {};
	    	$.ajax({
	    		url:'/admin/apply/bySerial',
	    		type:'post',
	    		async:false,
	    		dataTpye:'json',
	    		data:{"applySerial":data.applySerial},
	    		success:function(result){
	    			objDate = result.data;
	    		},
	    		error:function(result){
	    			console.log(result);
	    		}
	    	})
	    	if(obj.event =='showMessage2'){
	    		layer.open({
	    			type:1,
	    			title:false,
	    			colseBtn:false,
	    			area:'650px;',
	    			shade:0.8,
	    			id:'messageDetials2', //设定一个id，防止重复弹出
	    			btn:['确定'],
	    			btnAlign: 'c',
	    			moveType: 1 ,//拖拽模式，0或者1
	    			content:'<div><table class="layui-table"><thead><tr><th>申请编号</th><th>申请时间</th><th>状态</th>'
	        			+'</tr></thead><tbody><tr><td>'+objDate.applySerial+'</td>'
	        			+'<td>'+objDate.applyTime+'</td><td>'+objDate.status+'</td></tr></tbody></table></div>'
	    		});
	    	}
	    });
	    var active ={
	    	search:function(){
	    		var keyWord = $("#material_search").val();
	    		keyWord = "%"+keyWord+"%";
	    		table.reload('userAnalysis',{
	    			url:'/admin/material/userAnalysis',
	    			where:{
	    				keyWord:keyWord,
	    				tName:loginName
	    			},
	    			page:{
	    				curr:1
	    			}
	    		});
	    	},
	    	search2:function(){
	    		var keyWord = $("#material_search2").val();
	    		keyWord = "%"+keyWord+"%";
	    		console.log(keyWord);
	    		table.reload('userAnalysis2',{
	    			url:'/admin/detials/userAnalysis',
	    			where:{
	    				keyWord:keyWord,
	    				tName:loginName
	    			},
	    			page:{
	    				curr:1
	    			}
	    		})

	    	}
	    };
	    $('.layui-btn').on('click', function(){
	        var othis = $(this), method = othis.data('method');
	          	active[method] ? active[method].call(this, othis) : '';
	    });
});

function userAnalysis(){
	var year_before = $("#selectYears").val();//获得所选年份

	var year_min = parseInt(year_before)+1;

	var tName = "杨振刚";

	var years = "%"+year_before+"-"+year_min+"%";


	var title_o = year_before+"-"+year_min+"学年第一学期";

	var title_t = year_before+"-"+year_min+"学年第二学期";


		$.ajax({
		url:'/admin/course/highcharts',
		async:false,
		type:'post',
		dataTpye:'json',
		data:{"tName":tName,"classTrem":years},
		success:function(result){

		$('#userContainer').highcharts({
	        chart: {
	            type: 'column'
	        },
	        title: {
	            text: '学期申报/征订教材量'
	        },
	        xAxis: {
	            categories: [
	                title_o,
	                title_t,
	            ],
	            crosshair: true
	        },
	        yAxis: {
	            min: 0,
	            title: {
	                text: '数量（本）'
	            }
	        },
	        tooltip: {
	            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
	            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
	            '<td style="padding:0"><b>{point.y:.1f} 本</b></td></tr>',
	            footerFormat: '</table>',
	            shared: true,
	            useHTML: true
	        },
	        plotOptions: {
	            column: {
	                borderWidth: 0
	            }
	        },
	        series: [{
	            name: '申报',
	            data: [result.materialCountX, result.materialCountY]
	        }, {
	            name: '征订',
	            data: [result.applyCountX, result.applyCountY]
	        }]
	    });
		},
		error:function(result){
			console.log(result);
		}
	});
};


</script>
</body>
</html>